﻿using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VLine.Params;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRIssueFeedBLL: IT_VRIssueFeedBLL
    {
        /// <summary>
        ///  获取问题反馈列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<FeedBackModels> GetFeedBackList(FeedListModel model)
        {
            List<FeedBackModels> result = new List<FeedBackModels>();
            List<FeedBackResult> list = DBSession.IT_VRIssueFeedDAL.GetFeedBackList(model);
            if (list.Count <= 0)
                return result;
            List<int> ids = list.Select(s => s.id).ToList();
            //图片列表
            List<FeedPicture> picList = DBSession.IT_VRIssueFeedDAL.GetFeedPicture(ids);
            //问题回复列表
            List<FeedReply> replyList = DBSession.IT_VRIssueFeedDAL.GetFeedReply(ids);
            list.ForEach(o =>
            {
                List<FeedPicture> p = new List<FeedPicture>();
                List<FeedReply> r = new List<FeedReply>();
                FeedBackModels obj = new FeedBackModels
                {
                    id = o.id,
                    feed_title = o.feed_title,
                    feed_status = o.feed_status,
                    feed_content = o.feed_content,
                    user_name = o.user_name,
                    user_phone = o.user_phone,
                    login_name = o.login_name,
                    create_date = o.create_date,
                    header_url = o.header_url?.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))),
                    folder_id = o.folder_id,
                    folder_name = o.folder_name,
                    en_name = o.en_name
                };
                //图片地址
                var q = picList.Where(s1 => s1.feed_id == o.id)?.ToList();
                q?.ForEach(n => p.Add(new FeedPicture { id = n.id, feed_id = n.feed_id, img_url = n.img_url?.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) }));
                obj.pictue = p;
                //回复列表
                var s = replyList.Where(s2 => s2.feed_id == o.id)?.ToList().OrderByDescending(n => n.reply_date)?.ToList();
                s?.ForEach(m => r.Add(new FeedReply
                {
                    id=m.id,
                    feed_id=m.feed_id,
                    reply_date=m.reply_date,
                    reply_content=m.reply_content,
                    user_name=m.user_name,
                    login_name=m.login_name,
                    header_url=m.header_url?.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")))
                }));
                obj.reply = r;
                result.Add(obj);
            });
            return result;
        }
    }
}